// pages/mine/mine.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    const userRole = wx.getStorageSync('userRole')
    const userName = wx.getStorageSync('realName')
    const userAccount = wx.getStorageSync('userAccount')
    console.log(userRole)
    this.setData({
      userRole,
      userName,
      userAccount
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },

  onChange(event) {
    // event.detail 的值为当前选中项的索引
    this.setData({
      active: event.detail
    });
    if (event.detail === 0) {
     
      const userRole = wx.getStorageSync('userRole')
  
      if (userRole === 2) {
        wx.redirectTo({
          url: '/pages/chef-home/chef-home',
        })
      } else if (userRole === 5) {
        wx.redirectTo({
          url: '/pages/warehouse-home/warehouse-home',
        })
      } else if (userRole === 3) {
        wx.redirectTo({
          url: '/pages/admin-home/admin-home',
        })
      } else if (userRole === 4) {
        wx.redirectTo({
          url: '/pages/supplier-home/supplier-home',
        })
      } else if (userRole === 7) {
        wx.redirectTo({
          url: '/pages/regulation-home/regulation-home',
        })
      } else if (userRole === 6) {
        wx.redirectTo({
          url: '/pages/finance-home/finance-home',
        })
      } else if (userRole === 8) {
        wx.redirectTo({
          url: '/pages/purchaser-home/purchaser-home',
        })
      }


    }
  },
  loginOut() {
  
    wx.reLaunch({
      url: '/pages/login/login',
    })
    app.globalData = {
      applyType: 0,
      userInfo: null,
      isIpx: false,
      userId: "",
      canteensList: [],
      token: "",
      orderList: [],
      estimatedTime: '',
      estimatedNum: '',
    }
    wx.clearStorageSync()
  },
  toStat(){
    wx.navigateTo({
      url: '/pages/stat-home/stat-home',
     
    })
  }

})